package com.ssm.hj.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.hj.page.Page;
import com.ssm.hj.search.MenuSearch;
import com.ssm.hj.service.MenuService;
import com.ssm.hj.view.MenuView;
import com.ssm.mapper.MenuMapper;
import com.ssm.pojo.Menu;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {
    @Resource
    private MenuMapper menuMapper;
    @Override
    //根据用户查询角色具有的菜单
    public List<MenuView> queryUserByIdService(int userId) throws Exception {
        return this.menuMapper.queryUserById(userId);
    }

    @Override
    //阿杰 查询子级菜单
    public PageInfo<Menu> queryMenuChildAllService(Page<MenuSearch> page) throws Exception {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        return new PageInfo<Menu>(this.menuMapper.queryMenuChildAll(page.getSearchObj()));
    }

    @Override
    //阿杰 查询父级菜单
    public List<Menu> queryMenuParentAll() throws Exception {
        return this.menuMapper.queryMenuParentAll();
    }

    @Override
    //阿杰 修改菜单状态
    public int updateMenuStateService(int id, int state) throws Exception {
        return this.menuMapper.updateMenuState(id,state);
    }
}
